package com.blockmeta.bbs.immodule.adapter;

import androidx.annotation.Nullable;
import android.view.View;

import com.blockmeta.bbs.baselibrary.base.adapter.BaseAdapter;
import com.blockmeta.bbs.baselibrary.net.callback.BaseResponseCallBack;
import com.blockmeta.bbs.baselibrary.utils.LoadPicUtil;
import com.blockmeta.bbs.businesslibrary.util.RouterActivityHelper;
import com.blockmeta.bbs.businesslibrary.widget.CircleImageView;
import com.blockmeta.bbs.immodule.R;
import com.blockmeta.bbs.immodule.bean.HongbaoDetail;
import com.blockmeta.bbs.immodule.corebean.Impl.IMApplicationContext;
import com.blockmeta.bbs.immodule.dao.IMUserEntity;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class HongbaoGetDetailAdapter extends BaseAdapter<HongbaoDetail.CandyKidsListBean, BaseViewHolder> {

    private long mChatGroupId;

    public HongbaoGetDetailAdapter(int layoutResId, @Nullable List<HongbaoDetail.CandyKidsListBean> data, long chatGroupId) {
        super(layoutResId, data);
        mChatGroupId = chatGroupId;
    }

    @Override
    protected void convert(BaseViewHolder helper, final HongbaoDetail.CandyKidsListBean item) {

        IMApplicationContext.getUserDomainService().getUser(item.getUserId(), false, new BaseResponseCallBack<String, IMUserEntity>() {
            @Override
            public void fail(String msg) {
            }

            @Override
            public void success(IMUserEntity iMUserEntity) {
                CircleImageView avatar = helper.getView(R.id.contacts_avatar);
                LoadPicUtil.loadWithPicasso(avatar, item.getLogo());

                helper.setText(R.id.contacts_name, IMApplicationContext.getCircleDomainService().getCircleRemarkName(iMUserEntity, mChatGroupId));
                helper.setText(R.id.tv_coin_num, "+ " + item.getCandyNum() + "金币");

                avatar.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        RouterActivityHelper.openUserCenter(mContext, String.valueOf(item.getUserId()));
                    }
                });
            }
        });
    }
}
